<template>
	<view class='productSort'>
		<view class='header'>
			<u-row>
				<u-col span="3">
					<text class="iconfont icon-anke"></text>

				</u-col>
				<u-col span="2">

				</u-col>
				<u-col span="4">
					<u-tabs lineWidth='40' lineColor='#00aa7f' :list="list1" @click="click"></u-tabs>
				</u-col>

				<u-col span="2">


				</u-col>
				<u-col span="1">
					<text class="iconfont icon-sousuo"></text>

				</u-col>

			</u-row>
		</view>
		<view class='aside' :style="{bottom: tabbarH + 'px',height: height + 'rpx'}">
			<scroll-view scroll-y="true" scroll-with-animation='true' style="height: 100%;">
				<view class='item acea-row row-center-wrapper' :class='index==navActive?"on":""'
					v-for="(item,index) in productList" :key="index" @click='tap(index,"b"+index)'>
					<text>{{item.title}}</text>
				</view>
			</scroll-view>

		</view>
		<view class='conter'>
			<scroll-view scroll-y="true" :scroll-into-view="toView" :style='"height:"+height+"rpx;"' @scroll="scroll"
				scroll-with-animation='true'>
				<block v-for="(item,index) in productList" :key="index">

					<view class='listw' :id="'b'+index">
						<view class='title acea-row row-center-wrapper'>
							<view class='line'></view>
							<view class='name'>{{item.title}}</view>
							<view class='line'></view>
						</view>
						<u-empty v-if='item.children==null&&index==0' mode="list" iconSize='60'>
						</u-empty>
						
						<view v-else class='list acea-row'>
							<block v-for="(itemn,indexn) in item.children" :key="indexn">
								<navigator hover-class='none' :url='itemn.avatar'
									class='item acea-row row-column row-middle'>
									<view class='picture'>
										<image :src='itemn.avatar'></image>
									</view>
									<view class='name line1'>{{itemn.title}}</view>
									<view class='name line1' style="display: flex;">

										<text class="iconfont icon-fire-fill"></text>
										{{itemn.heatDeg}}
									</view>
								</navigator>
							</block>
						</view>
					</view>
				</block>
				<view :style='"height:"+(height-300)+"rpx;"' v-if="number<15"></view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		handleTree
	} from '@/utils/ruoyi.js'
	import {
		listZone,
		myZone
	} from '@/api/safe/zone.js';
	
	export default {
		data() {
			return {
				navlist: [],
				productList: [],
				navActive: 0,
				number: "",
				height: 0,
				hightArr: [],
				toView: "",
				tabbarH: 0,
				list1: [{
					name: '分类',
				}, {
					name: '关注',
				}]
			}
		},
		onLoad(options) {
			this.getAllCategory();
		},
		onShow() {},
		methods: {
			infoScroll: function() {
				let that = this;
				let len = that.productList.length;
				let child = that.productList[len - 1] && that.productList[len - 1].child ? that.productList[len - 1]
					.child : [];
				this.number = child ? child.length : 0;

				//设置商品列表高度
				uni.getSystemInfo({
					success: function(res) {
						that.height = (res.windowHeight) * (750 / res.windowWidth) - 98;
					},
				});
				let height = 0;
				let hightArr = [];
				for (let i = 0; i < len; i++) {
					//获取元素所在位置
					let query = uni.createSelectorQuery().in(this);
					let idView = "#b" + i;
					query.select(idView).boundingClientRect();
					query.exec(function(res) {
						let top = res[0].top;
						hightArr.push(top);
						that.hightArr = hightArr
					});
				};
			},
			tap: function(index, id) {
				this.toView = id;
				this.navActive = index;
			},
			getAllCategory: function() {
				let that = this;
				listZone().then(async res => {
					that.productList = handleTree(res.data, 'zoneId', 'parentId');
					let res2 = await myZone()
					that.productList.unshift({
						zoneId: 0,
						title: '我的',
						children: res2.data
					})
					console.log(that.productList)
					setTimeout(function() {
						that.infoScroll();
					}, 500)

				})

			},
			scroll: function(e) {
				let scrollTop = e.detail.scrollTop;
				let scrollArr = this.hightArr;
				for (let i = 0; i < scrollArr.length; i++) {
					if (scrollTop >= 0 && scrollTop < scrollArr[1] - scrollArr[0]) {
						this.navActive = 0
					} else if (scrollTop >= scrollArr[i] - scrollArr[0] && scrollTop < scrollArr[i + 1] - scrollArr[
							0]) {
						this.navActive = i
					} else if (scrollTop >= scrollArr[scrollArr.length - 1] - scrollArr[0]) {
						this.navActive = scrollArr.length - 1
					}
				}
			},
			searchSubmitValue: function(e) {
				if (this.$util.trim(e.detail.value).length > 0)
					uni.navigateTo({
						url: '/pages/goods_list/index?searchValue=' + e.detail.value
					})
				else
					return this.$util.Tips({
						title: '请填写要搜索的产品信息'
					});
			},
		}
	}
</script>

<style scoped lang="scss">
	.productSort .header {
		// margin-top: var(--status-bar-height);
		height: 78rpx;
		background-color: #fff;
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		z-index: 9;
		border-bottom: 1rpx solid #f5f5f5;
	}



	.productSort .aside {
		position: fixed;
		width: 180rpx;
		left: 0;
		top: 0;
		background-color: #f7f7f7;
		overflow-y: scroll;
		overflow-x: hidden;

		height: auto;
		margin-top: 78rpx;
	}

	.productSort .aside .item {
		height: 100rpx;
		width: 100%;
		font-size: 26rpx;
		color: #424242;
	}

	.productSort .aside .item.on {
		background-color: #fff;
		border-left: 4rpx solid #00aa7f;
		width: 100%;
		text-align: center;
		color: #00aa7f;
		font-weight: bold;
	}

	.productSort .conter {
		margin: 78rpx 0 0 180rpx;
		padding: 0 14rpx;
		background-color: #fff;
	}

	.productSort .conter .listw {
		padding-top: 20rpx;
	}

	.productSort .conter .listw .title {
		height: 90rpx;
	}

	.productSort .conter .listw .title .line {
		width: 100rpx;
		height: 2rpx;
		background-color: #f0f0f0;
	}

	.productSort .conter .listw .title .name {
		font-size: 28rpx;
		color: #333;
		margin: 0 30rpx;
		font-weight: bold;
	}

	.productSort .conter .list {
		flex-wrap: wrap;
	}

	.productSort .conter .list .item {
		width: 177rpx;
		margin-top: 26rpx;
	}

	.productSort .conter .list .item .picture {
		width: 120rpx;
		height: 120rpx;
		border-radius: 50%;
	}

	.productSort .conter .list .item .picture image {
		width: 100%;
		height: 100%;
		border-radius: 50%;

		div {
			background-color: #f7f7f7;
		}
	}

	.productSort .conter .list .item .name {
		display: flex;
		justify-content: center;
		font-size: 24rpx;
		color: #333;
		height: 56rpx;
		line-height: 56rpx;
		width: 120rpx;
		text-align: center;
	}

	.demo-layout {
		height: 70rpx;
		border-radius: 4rpx;
	}

	.bg-purple {
		background: #CED7E1;
	}

	.bg-purple-light {
		background: #e5e9f2;
	}

	.bg-purple-dark {
		background: #99a9bf;
	}

	.icon-sousuo {
		font-size: 50rpx
	}

	.icon-anke {
		font-size: 50rpx;
		color: #00aa7f;
		padding-left: 20rpx;
	}

	.icon-fire-fill {
		color: #908495;
	}

	.icon-huixingzhen {
		font-size: 100rpx;
		color: #cdcdcd
	}
</style>